package battleship.setup;

import battleship.Controller;
import battleship.PluginSetup;
import battleship.Setup;
import battleship.boat.Boat;
import battleship.player.Player;
import battleship.view.Views;

public class SetBoats implements PluginSetup {

	@Override
	public String setupGetFunction() {
		return "set"; //the command this plugin handles
	}

	@Override
	public int setupExecFunction(Player player, Boat boat, String[] arguments) {
		
		boolean correctPosition = false;
		
		while (!correctPosition) {
			correctPosition = Setup.setBoat(player, boat, arguments[0]);
			if (correctPosition) {
				
				Controller.getController().printBoard(true, player.getField()); // show the field for visual confirmation
				
				boolean goodSetup = Controller.getConsole().scanYesNo("Is deze positie goed?");
				
				if(!goodSetup)
				{
					return 3;
				}
				


				
				
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}

	@Override
	public String setupGetDescription() {
		return "stel de positie van de boot in";
	}

	@Override
	public String setupGetOptions() {
		return "[a1h] coördinaten[a1] + horizontaal[h]/verticaal[v]";
	}

	@Override
	public boolean allAtOnce() {
		return false;
	}

	@Override
	public boolean setupErrorHandler(int error) {
		//0 = good setup
		//1 = conflict
		//2 = bad input
		//3 = go again no feedback
		switch (error) {
		case 0:
			System.out.printf("\nDe boot is nu ingesteld\n");
			return true;
		
		case 1:
			System.out.printf("\nDeze positie is ongeldig\n");
			return false;
			
		case 2:
			System.out.printf("\n%s\t%s\n", setupGetFunction(), setupGetOptions());
			return false;
			
		case 3:
			return false;

		default:
			break;
		}
		return false;
	}

	@Override
	public void onFinish(Player player) {
		//nothing to do here
		
	}

	@Override
	public Views[] setupSupportedViews() {
		return (new Views[] {Views.Console});
	}

}
